package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.IVerifyService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  用户邮件激活
 *
 */
@RestController
@RequestMapping("/user")
public class VerifyController {

    @Reference(timeout = 3000)
    IVerifyService verifyService;


    @RequestMapping("verify")
    @Anoymous
    public ResponseData verify(String uid,String username){
        // 用户激活,更改用户表和用户验证表中的is_verify字段值就可以了
        UserVerifyRequest verifyRequest = new UserVerifyRequest();
        verifyRequest.setUuid(uid);
        verifyRequest.setUserName(username);
        UserVerifyResponse verifyResponse = verifyService.userVerify(verifyRequest);
        // 根据code值判断是否激活成功
        if(verifyResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return new ResponseUtil<>().setData(null);
        }
        // 激活失败
        return new ResponseUtil<>().setErrorMsg(verifyResponse.getMsg());

    }
}
